import { createRouter, createWebHashHistory } from "vue-router";
import Store from "../store/index"

let user = Store.state.user
if (user === null) {
    user = { role: "" }
}
const routes = [{
    path: "/mallMain",
    component: () =>
        import("../view/MallMain.vue"),
    redirect: "./Home",
    children:[{
        path: "/Home",
        component:()=>import("../view/client/Home.vue"),
    },{
        path: "/GoodsInfo",
        component:()=>import("../view/client/GoodsInfo.vue")
    },{
        path: "/Type",
        component:()=>import("../view/client/Type.vue")
    },{
        path: "/SellerInfo",
        component:()=>import("../view/client/SellerInfo.vue")
    },{
        path: "/Collect",
        component:()=>import("../view/client/Collect.vue")
    },{
        path: "/Address",
        component:()=>import("../view/client/Address.vue")
    },{
        path: "/Shop",
        component:()=>import("../view/client/Shop.vue")
    },{
        path:"/Order",
        component:()=>import("../view/client/OrderInfo.vue")
    }]
},
{
    path: "/",
    component: () =>
        import("../view/Login.vue")
}, {
    path: "/register",
    component: () =>
        import("../view/Register.vue")
}, {
    path: "/Main",
    component: () =>
        import("../view/Main.vue"),
    redirect: user.role === "admin" ? "./Adminhome" : "./sellerHome",
    children: [{
        path: "/Adminhome",
        component: () =>
            import("../view/admin/Home.vue")
    }, {
        path: "/AdminTypeInfo",
        component: () =>
            import("../view/admin/TypeInfo.vue")
    }, {
        path: "/AdminSellerInfo",
        component: () =>
            import("../view/admin/SellerInfo.vue")
    }, {
        path: "/AdminUserInfo",
        component: () =>
            import("../view/admin/UserInfo.vue")
    }, {
        path: "/AdminGoodsInfo",
        component: () =>
            import("../view/admin/GoodsInfo.vue")
    }, {
        path: "/sellerHome",
        component: () =>
            import("../view/seller/Home.vue")
    }, {
        path: "/personInfo",
        component: () => import("../view/admin/PersonInfo.vue")
    }, {
        path: "/sellerGoods",
        component: () => import("../view/seller/SellerGoods.vue")
    },{
        path: "/AddressInfo",
        component:()=>import("../view/admin/AddressInfo.vue")
    },{
        path: "/AdminNotice",
        component:()=>import("../view/admin/Notice.vue")
    },{
        path: "/AdminManage",
        component:()=>import("../view/admin/ManageInfo.vue")

    },{
        path: "/AdminCollect",
        component:()=>import("../view/admin/CollectInfo.vue")
    },{
        path: "/AdminShop",
        component:()=>import("../view/admin/ShopInfo.vue")
    },{
        path: "/AdminOrder",
        component:()=>import("../view/admin/OrderInfo.vue")
    }]
}]

const router = createRouter({
    history: createWebHashHistory(),
    routes
})

export default router